package API.Generic;

import java.util.Arrays;

public class MyGenericClass<E> {
    private Object[] obj = new Object[10];
    int size = 0;

    public MyGenericClass() {
    }

    public void add(E e) {
        if (size >= obj.length) {
            obj = Arrays.copyOf(obj, obj.length << 1);
            obj[size] = e;
        } else {
            obj[size] = e;
        }
        size++;
    }

    public void remove(E e) {
        int index = Arrays.binarySearch(obj, e);
        for (int i = index; i < size; i++) {
            obj[i] = obj[i + 1];
        }
        size--;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < size; i++) {
            sb.append(obj[i]).append(" ");
        }
        return sb.toString();
    }
}
